#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5,M=1e6+5;
const ll inf=4e18;
int n,len[N],b[M],c[M],cnt[M],x,y[N];
vector<int>a[N];
vector<pair<int,int> >oper[M];
int act[M];
ll ans[M];
int main()
{
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;scanf("%d",&x),len[i]=x,act[1]+=x;
		while(x--)scanf("%d",&y),a[i].push_back(y);
	}
	scanf("%d",&x);
	for(int i=1;i<=n;i++)scanf("%d",&y[i]);
	for(int i=1;i<=n;i++)for(int j=0;j<len[i]-1;j++)b[0]++,b[b[0]]=a[i][j+1]-a[i][j]+1;
	b[0]++,b[b[0]]=1;
	sort(b+1,b+b[0]+1),b[0]=unique(b+1,b+b[0]+1)-b-1;
	for(int i=1;i<=n;i++)for(int j=0;j<len[i]-1;j++)
	{
		int pos=lower_bound(b+1,b+b[0]+1,a[i][j+1]-a[i][j]+1)-b;
		oper[pos].push_back({i,j});
	}
	for(int i=1;i<=n;i++)for(auto j:a[i])c[0]++,c[c[0]]=j;
	sort(c+1,c+c[0]+1),c[0]=unique(c+1,c+c[0]+1)-c-1;
	for(int i=1;i<=n;i++)for(auto &j:a[i])j=lower_bound(c+1,c+c[0]+1,j)-c,cnt[j]++;
	ll res=0;
	for(int i=1;i<=c[0];i++)res+=1ll*cnt[i]*y[cnt[i]];
	ans[1]=res+1ll*b[1]*act[1]*x;
	for(int i=2;i<=b[0];i++)
	{
		act[i]=act[i-1],ans[i]=ans[i-1]-res;
		for(auto j:oper[i])
		{
			int pos=a[j.first][j.second+1];
			res-=1ll*cnt[pos]*y[cnt[pos]];
			cnt[pos]--;
			res+=1ll*cnt[pos]*y[cnt[pos]];
			act[i]--;
		}
		ans[i]+=res+1ll*act[i-1]*(b[i]-b[i-1]-1)*x+1ll*act[i]*x;
	}
	ll anss=inf;
	for(int i=1;i<=b[0];i++)anss=min(anss,ans[i]);
	vector<int>ans1;
	for(int i=1;i<=b[0];i++)if(ans[i]==anss)ans1.push_back(b[i]);
	printf("%lld %d\n",anss,(int)ans1.size());
	for(auto i:ans1)printf("%d ",i);printf("\n");
	return 0;
}